#  Copyright (c) 2014-present, Facebook, Inc.
#  All rights reserved.
#
#  This source code is licensed as defined on the LICENSE file found in the
#  root directory of this source tree.

load("//tools/build_defs/oss/osquery:cxx.bzl", "osquery_cxx_library")
load("//tools/build_defs/oss/osquery:native.bzl", "osquery_target")
load("//tools/build_defs/oss/osquery:platforms.bzl", "FREEBSD", "LINUX", "POSIX", "WINDOWS")
load("//tools/build_defs/oss/osquery:third_party.bzl", "osquery_tp_target")

osquery_cxx_library(
    name = "core",
    srcs = [
        "flags.cpp",
        "init.cpp",
        "query.cpp",
        "system.cpp",
        "tables.cpp",
        "watcher.cpp",
    ],
    header_namespace = "osquery/core",
    exported_headers = [
        "watcher.h",
    ],
    exported_platform_headers = [
        (
            WINDOWS,
            [
                "windows/handle.h",
                "windows/ntapi.h",
                "windows/wmi.h",
            ],
        ),
    ],
    exported_post_platform_linker_flags = [
        (
            FREEBSD,
            [
                "-lcrypto",
                "-lgflags",
                "-lglog",
            ],
        ),
    ],
    platform_deps = [
        (
            LINUX,
            [
                osquery_tp_target("util-linux"),
            ],
        ),
    ],
    platform_srcs = [
        (
            POSIX,
            [
                "posix/initializer.cpp",
            ],
        ),
        (
            WINDOWS,
            [
                "windows/handle.cpp",
                "windows/initializer.cpp",
                "windows/wmi.cpp",
            ],
        ),
    ],
    tests = [
        osquery_target("osquery/core/tests:flags_tests"),
        osquery_target("osquery/core/tests:system_tests"),
        osquery_target("osquery/core/tests:tables_tests"),
        osquery_target("osquery/core/tests:watcher_permissions_tests"),
        osquery_target("osquery/core/tests:query_tests"),
    ],
    visibility = ["PUBLIC"],
    deps = [
        osquery_target("osquery:headers"),
        osquery_target("osquery/config:config"),
        osquery_target("osquery/core/plugins:plugins"),
        osquery_target("osquery/core/sql:core_sql"),
        osquery_target("osquery/filesystem:osquery_filesystem"),
        osquery_target("osquery/process:process"),
        osquery_target("osquery/utils:utils"),
        osquery_target("osquery/utils/conversions:conversions"),
        osquery_target("osquery/utils/info:info"),
        osquery_target("osquery/utils/system:env"),
        osquery_target("osquery/utils/system:system_utils"),
        osquery_target("osquery/utils/system:time"),
        osquery_target("osquery/logger:logger"),
        osquery_tp_target("gflags"),
        osquery_tp_target("glog"),
        osquery_tp_target("openssl", "crypto"),
        osquery_tp_target("glibc", "pthread"),
    ],
)
